﻿function countDown(startTime, divid, the_event) {
    var tdiv = document.getElementById(divid)
        , start = parseInt(startTime.getTime(), 10)
        , the_event = the_event || startTime.toLocaleString()
        , to;
    this.rewriteCounter = function () {
        var now = new Date().getTime()
          , diff = Math.round((start - now) / 1000);
        if (startTime > now) {
            //dday=Math.floor(diff/(60*60*1000*24)*1)
            dhour = Math.floor((diff / (60 * 60)))
            dmin = Math.floor(((diff / 60) - (dhour * 60)))
            dsec = diff - (dmin * 60) - (dhour * 60 * 60)
            tdiv.innerHTML = "Thời gian còn: " + dhour + ":" + dmin + ":" + dsec;
        }
        else { clearInterval(to); }
    };
    this.rewriteCounter();
    to = setInterval(this.rewriteCounter, 1000);
}